Restructure JS, future-friendly functions