fix some possible crashes and off-by-1 errors
Release 0.0.2