Add comments and make class more modular (so solve method can be easily called during testing)