logical errors in distinct function...