Added code for exception handling