added mutex lock and unlock funtionality