Added input handlers, some math functions, and updated states.