Function optimization and js fix