Fixed some math functions and added more exceptions.