refactor and more functions