finished implementation of rebuild