refactor javascript view