most of valid.cpp can go i think