Fixed a major bug that caused the entire script to fail. Function came inside the error handling block and couldnt be seen