refactored code, water logging