Refactors input handling a bit