fixing many bugs