refactored and saving code