Write tests, fix up some validation