major refactoring work and adding definition stuff