Javascript restructualization