refactored to save a few lines
further refactoring to save lines