fixed a few coding bugs