WARNING: Messy Code

It gets the job done, though.