This is dirty as all hell... but it works