Fix bug and integration test