Fix for weird situation of nested elements

and jslint, code style and documentation fixed