Spec tests and bug fixes

Finished up adding spec tests, rcov shows 100% coverage now. Found various issues
to fix in the process of writing specs, so fixed those.