added tests
fix executable perm
fix a few off-by-one errors