js functions improved, more comments