solving issue #4 and improve testing with more cases