Added happy flow unit tests and fixed some bugs.