improved cmake, added stats and debug option, changed communication interface