more refactoring for study
fixed compile errors