moved before hooks before any validation
added some early returns on invalid doc