branch is only a prototype, fixed a couple bugs