Added loggedin check