Minor fixes from code review and make test more robust