Fixes by cjm721

Added perms and cleaned up code.