fixes, end-to-end tests

@feiranwang  This file needs comments throughout. Especially one explaining what is doing.