Some modifications made to https://sf.net/p/qtrpt