many bug fixes, fixed #8