Some refractoring, and fixing