Refactored code, start on defs/refs.