Javascript code refactorization.
Started