Refactor code and add mongodb session for express