Major 'make-sense' refactoring and fixed some ugliness