modified for exception handling