Okay, this should work, but the script is still ugly