created 2 helper functions and added comments