Fixing problem with exception throwing