fixed resource problem and sorting problem