Refactor input handling and purchase logic