Add Chmod implementation. Fixes to bit flip bugs.