Moved last ID variable line to proper place

- move last insert ID line to the right place so it saves the variable correctly;