version supporting motive 1.7, with prints for debugging
cleaner version without prints for debugging