moving functions and logic outside of the apply controller