refactored and fixed formatting