Moved logic. Improved permissions