refactored to use scanner class