Refactored process hook to simplify code.