added some logic to handle different kinds of users