added code to check whether logged in, redirect to login if not