controller code refractor