some refactoring and start on tests
Tests for stacked graph improvements, ehem...