Move write method in controller