Minor refactoring, removed some defs, added some tests