Thats the same code I'm using, but seems like having issues when I catch pokemon sometimes. I check the stats screen with the grid and sometimes stays will be skewed instead of perfectly balanced. So not sure what's going on.
Also, do you know if this works for breeding when a pokemon is gonna...