Remove debugging code and refactor few lines