Added error handling and logging in scripts to help debugging later