Fixed bug in fn generation