trying to combine livhs' forked version with nuritme's version