organized js code, renamed z variable