tidy with forelse
prevent error if user is not logged in
refactored :)
tidy up
refactor