Thread safety and code simplification