Refactor javascript code separating it into files.