More work on permissions and some refactoring of date stuff.