More testing, refactoring