Refactoring (formatting plus other stuff that needs testing).
Fix warnings