Fixed global variable, added login_required