- some fixes for multiple definition errors
- refactoring for effeciency