Completly revised version of qi.php

Some changes to the last commit of nickvergessen