Consolidated all shared functions into 1 file

Also reduced visual clutter in the example templates