Added some error handling
Merge + sort fix