refactor and reorder
Merge branch 'master' of https://github.com/maxdeliso/twig
signedness fixes