Some refactoring and house keeping.