Fix bugs found with Adam

G'day,

I've been helping Adam with using this. We found a couple of bugs when running on linux. This hasn't been tested with Mac OSX et al. yet.

Cheers,
Kevin