Refined login module with global variable issues