implementation of direct solver