implement some part of the insert function