Move input scanning into a separate method