minor fix for the bug, added code to handle the exceptions