#9 restructure architecture and improve algorithm