added simple test cases
small tweaks, handle edge cases