Possible bug fixed, and some cleanup.