Javascript almost done.. must refactor