All js code moved to functions