Making use of ATOMIC_BLOCK instead of manual code