Fixed a few bugs in gaincal generation