moved check_directories (for right permissions) after fix_permissions and drop_privileges