Quick fix
Fixed an infinite recursive loop
Catch correct exceptions
Formatting