refactored test to use utility function in place of writing out the loop