some refactoring, remove debug