some big refactoring
more progress