Refactored input to accept stdin instead of arguments.