Prettify

Made the script a little bit more readable and mantainable, along with a couple of small bugfixes. Testing suggests that the Beeminder API problems don't stem from these changes.