updated for exception handling