code refractored + some move repair