THIS CODE WORKS. DO NOT MESS WITH IT FURTHER. UNLESS IT ACTS STUPID.