add headers controller and refactor code