porting types/type util function (bytes) from optimize branch.
merging in merges from merge into merge from merge that was merging optimize into master into optimize