updated source with exception handling