Added Q parameter - this seriously needs to be redesigned into something nicer using numpy functionality