complete refactor / rewrite