refactored login, script still functioning perfectly