Initial version. Sloppy error handling and unflexible calculations.