Database scripts model, some bugs fixed