big mess, refacter needed, but these changes have to be saved