refactor and fixing