Fix write barriers

Using only read barriers was incorrect. Now add the correct write
barriers and use them when necessary.