Merge pull request #1 from rgs/master

Some cleanups and robustness fixes