handle more error cases, clean up some things splint found