Code for algorithms