use prototype method
improve script by adding some checks and going through fields recursively