Major refactor towards thread safety;