Fix findLastCode func