Move if lastTable and lastId to related method