Fix some minor bugs where wrong Exception being raised