Fix some bugs in the controller generator