Corrected implementation of listp