refactoring for integration in building system and bug fixes