Fixes many bugs