Add comments and improve code clarity.