forked from the original by Cyrill Gorcunov