Improved DOM handling of elements, added visibility support