simplification and schema checks
removed buggy type casting
minor tweaks