almost completed logic