Generate controller function working now