javascript : fixed bugs and make behaviour fancier