Warning fixes, debug fix, new permissions

This is only a start, I've underestimated the mess here =/