refining & commenting code in js