some cleanup with help from truth5678