Fixing sync forEach bug