Cleanup code, add comments, etc