Added database versioning and minor fixes