add comments and improve code appearance