added cookie session, refactored common handler