Some modifications and tests. Suddently think I should switch back to bit masks for portability reasons