Updated to use complex numbers, added more functions.