Finished advance function. UNTESTED.