Shortened code into fewer lines and added link to a fiddle demo.