Fixes #151 and #173

Apply fix suggested by @jcsahnwaldt