Fix bugs in controller