pasting misc. code for SLAM collected from inbox (from circa 2007)