refactored to make input asynchronous