Close div in wrong place causes HTML error