re-write of js to be a bit better formatted.