Refactored all code