fuck it - this isn't perfect, but I'm sick of wasting time on it