totally reworked this function to make it do somethign useful