Rewrite qs, bug fixes