bug fix code refactor