Done some refactoring and included external files