javascript re-organized