Added permissions, cleaned up code.