move and clean up code;
prepare for merge in master