first complete version, copied from PLT git