refactored all code