Changed atoms to refs, cause we are in transactions.
Eliminated one redundant return in dosync.