improved and tested MWD implementation