created helper methods and handled input errors