code refactoring and adding makefiles