refactored the run method