added exception handling