Added density formula; fixed a few minor bugs