Code cleanup; add integration test