Adding exception handling