[Working] refactored code