small code tweaks taken from wp.com