Polished up a bit, added some permissions checks