couple bugs fixed, seems correct now