Imported logic from login