made math functions use Long and other fixes