cleanup and some fixes