fixing up many bugs