fixes many bugs