Use better variable names in a few places and clean up a few functions