Make sure that empy list is not passed into function. There is some protection
but it may not be enough.