some fix and cleaning code