this kinda got a mess, but it might work