Some refactoring and whatnot