Complete source code for controller