Optimization

Optimized code for readability by putting each main task into its own
function.

Added input checking, which makes sure the input equation is valid, and
outputs "Invalid Syntax" if not.