Ugly functions. Encrypted to hide my shame.