Fix beforeWrite check