fixed bugs

bugs in error handling and change in "if" operator