Moved some code to cyvmath, a bit of cleanup