many fixes and cleanup