Add support for LID and improve the code a bit.