Code refactored/cleanup