control algorithm mostly implemented