Fixed bugs, modified codes for PR