some js refactoring... more to come...