many bugs fixed, including #5 and #3