refactor and minor changes