re-organize javascript