fix some problems and clean up