optimize code, add casting for m:m fields, fix undefined field erros in NoSQL engines