added more test cases, improved stability