Refactor javascript and add data type comment