Debugging for "types[i] is undefined" error