Refactored api and session modules to better split responsibilities