add comments and improve indentation