changes to Input handling, removing redendant varibles, streamlining and modularizing code