Finished new algorithm for Q3