Finally finished this shit and it's probably horribly efficient and idgaf k