Some more refactors and corrections