refactor: major refactors and code improvements