almost functioning refactored javascript yay