Some refactoring and such.