Moving helper code to controller