Refactor add function in courses controller