major refactoring
fixing bugs