Fix segfaults caused by empty lists

This was present in type conversion methods and in the definitions for
    head, tail, len, push and for