added exception handling and fixed typo in comment