refactored to remove duplication and level up our code

Signed-off-by: Andrew Deitrick <ajdeitrick@gmail.com>