Fixed broken test, also refactored code.