Adding in q calculation and word sequence generation