Better js logic