updated to try/catch instead of if/else