Changes to insert new targets on the db, and fix bug when the number of
targets are small, other minor changes