Implemented persisten authentication session, and cleaned the code for readability.