Add locking. This could also be replaced with a lock free increment, will do that later.