Finally got working code for invertSelection. Phew.