Fixed one merge issue of duplicate function, and fixed database failing due to unique key issues