add more test code from stackoverflow