clean up auto-merge

remove redundant code
generalise the functions for future projects