much improved version, many bug fixes, still exceptions