refactored a long method