Added integration tests and several other fixes