js refactored #1
small js changes
refactored functions