Added sessions and started refactoring older code.