lua rewerite to make similar to versor.js