Various refractoring and stuff.