bug fixes with type checking
merge latest master into branch