Javascript better design