fix the bug and use the simplest way to implement the code