Move permission checks into their own function