Completed implementation of add()