Okay, part one of fixing this clusterfuck of a function complete