fixed all compiler errors and a few runtime errors