cleaned up some error logic