Fixes issue where "head" is undefined in Safari 4. Also adds regresson test