A little bit of cleanup and attempt at functions returning functions