fixed a multiple conditional bug, added test cases, stable