fixed fatal mistake in sort function