Added check to get numbers sorted correctly