Code refactored and config fixed