updated sub-routines for readability