refactored and reordered defs