migrate DB to postgresql, fix minor bugs