decode algorithm complete