Fixed a sorting issue. Might have to optimize the method at some time.