some more refactoring
js slow on ff, fast on chrome...factor 5 :(