Refactor input parsing