Refactoring and improvements all over the place.