adl: moved adlstuff.pas inline, reformatted the code and removed duplication