Code clearence and refactoring