code ported

need to rename