moved trial code, tidy up