catching errors and logging better