Filled out code for the algorithms