made it thread safe and const