Moved back the console and error redirection to the beginning of JS code.