Part 1 of rewrite of functions