added some funct., and fixed bugs