More unit tests, fix compile bug in for