Fixed minor bug where exceptions were not being thrown correctly