Fix: add function to check rights and uniformize code