added hw5. refactored by moving functions to utilities