Added commentary, fixed a couple of bugs. V4