Rewrote certain helper functions to take advantage of function pointers.