Refactored. Code splited in files: core, session