Changed code to support MULTI THREADING