Added thread safety to Pools class