added comments, fixed code so that the list is not calculated twice