Removed unnecessary variables
Fixed try/catch block to check for exception with separate loop