cleaned up a bunch of things. script is mostly-working now.