added sort function + immediate scope updating