refactored sort algorithms to be more readable