implemented the twist-free function