Refactoring

Too many changes to list.