Remove unused code in controller, refactor and add tests to merge service