Made the code a bit more efficient by improving sorting algorithim.