the hacky fix to the underflow issue wasn't so hacky; added docs
cleanup and various small readability fixes