rebase: extract am code to new source file