refactored and small changes