updated few code to fix bugs