- added JSON encoding - fix problem where session was not closed - origin can now be decided by a custom module