finalizing operation 2 and 3, prepare 4, optimizations