refactort and comment core