Cleaning up dead code and adding some comments