Fixed input bug and cleaned up code.