Refactor javascript functions into JS files