Cleanup sources and repair some bugs.