Rewriting the Adam code

*