refactored input to handle pushing elements to stack