Big refactor after modularization