refactorig and formatting source code