cleaned up a couple things and hopefully works fine - untested