many small fixes and some cleanup