Fixes to fail elegantly when input is not of the expected type

check for type before doing type specific checks to avoid exceptions in array and integer