big refactor to support client