Refactor: process hash outside of lock

We are replacing the instance of @hash inside the synchronized block
which which decrease the amount of time we need to operate in a shared lock.