Solve method added with debugging.