Refactor and format JS code for layout model
Minor UI fixes and JS documentation comments