Added correct exception handling.