fixed the codes according to comments, will talk to Li on remaining problems