refactor and enhanced