Making classes thread safe