Refactored and fixed formatting