Add try/catch block and debugging messages