switched to try/catch instead of if/else