Merging @dstorey's PR #212 (had to resolve some conflicts locally first)