update comments and improve code.