Added barriers. Minor refactors