Several refactors and simplifications