Cleaned up the dom and shape detection a whole lot.