Added test, slight refactoring