refactored userkey/user related functions