Filled in rest of pseudocode