rewrite using c++ and application of new design

tower: https://tower.im/projects/8f19f0bf0e754f0b82ef2c24bc230973/todos/ab64a4ac2c914c7e9dbea25257a8cb9d/

Change-Id: Ic80fe5965c71625018c694eb9350fe9d6d6e50d5