Some more refactoring.. It is getting better, I think