Cleaned up header code a bit and wrapped everything up in functions