big refactor for cleaner codebase