major refactoring +tweaks. non-stable, working on adapting tests