fixed permission check

and some style stuff.