fixed some pretty badly written stuff.