Return userdata reffed add multithread locks on appdata
Reorganise header file