Cross thread safe code

Added code for making cross thread safe code