Fixed compiler and runtime errors