copy from Twinkler 1.2.1