Session handling added, some bugfixes.