refactor to incorporate gfgtdf's first set of changes