Optimized database write by adding new batch property function.  Refacto...

...r database write and various other code