refactor & fix bug