added thread control and readwritelock!!!