Refactor mode javascript code to static