Refactoring of Code and set up of API