fix prime tools bugs, add test cases