Trying to resolve Uncaught TypeError