minor fix and refactor