wip - new version
massive refactor for readability and cleanliness