refactor input management and data structures