Update lsm.py

updated with many changes