A bunch of code from here and there.