rewrite a load of crap code