datatype auto-detect logic changes bug fixes
some code cleanup