Add tests for exists and remove and fix bug in exists