Fixed some memory leaks and bugs in webserver and daemon