Cleaned up solver