Added more test code and renamed some things to make it more clear.