An implementation of the direct algorithm