Various refactoring changes

@evansb please review