Code clean up. Implemented solve()