resurrected login code, small reorg