Factorized some code
Debugging