Sorted, refactored and added tests.