Slight refactoring. Added some simple tests