fixing up some syntax and closures etc