Small cleanup.
Remove duplicate functions and put them in a shared file.