Implemented onBeforeFrame() and onAfterFrame() hooks