copied from master
rewrote