Fix memory leak; add Cakefile; extend event API; bug fixes.