fixed js logic