fixed a few bugs and runtime errors