further generalise
swap order of functions
remove duplicated function at last