Refactored and small changes