refactor the code to include controllers