Adapted some old code.