Implemented session logic. Refactored code, javascipt.