Fix compiler and runtime errors