copy from http://hyzhak.github.io/darlingjs