separate the AM code to its own file