completed/refactored (but havent compiled yet)