Updated calculation of Q and W_inv. Closes #3