Moved some of the function specific magic into a separate class