fixed the bugs from code merge