various changes and refactor