improve controller code