Massive refactoring: now works stable with jQuery, but does not work at all without it