Implement most of chmod

I am planning on cleaning this up a bit and finishing the TODOs later.