refactory main javascript to backbone style.