Code cleanup, and commenting