WIP: add end to end test. It currently fails occasionally