implement direct solver