Improved thread safety

Improved thread safety of the shared instances by using GCD dispatch_once tokens.