smarter JS initialization