add comments and fix formatting