outsourced some helper functions