removed unused code plus a couple bug fixes.