Cleaned up atomic code quite a bit