fix some bugs, more accurate now