Added topic handling, various bug fixes