more changes on generator. moved logic to database and used postgres hstore