refactored and created helper method