some crazy scripting stuff