Slightly refactored sorts and added test case