Fixed most of the references, applied #50/#51, and made the code more consistent