Improve primitive detection and fix integration test