Refactored procedures.xq