Fixed badly refactored code