fix naming issue and simplify the code