Special thanks to asqueella for ideas, advice, and fixes!