rebuilt last function