lots of minor changes to get things running, accurate working example in tests