fixed some problems and broken code