refactored to minimalize lines of code