fixed ensure, added more test code