cleanup mv code and fix small bug in refactoring