rewrite in prototype based to speed up, add BDD testing style, and fixed couple bugs.