General cleanup: adding comments and formatting