Rewrote login procedure