fixed some js logic