restructure tie implementation and add some tests