refactor and debug statements