break the core of add_motifs loop into a seperate function