fixed bug creating new records instead of updating existing ones