Fixed logic when updating values from database