Move low-level prefix stuff into key file
Fix depth, move prefix functions into key