minor refactor and debug