fixed lastpos bug in gen.py