fixed some bugs. added end to end tests