fixed my version of #3, #4 is completely fixed with test case.