Improve general js logic