ported code phase 1