Refactored code.

Signed-off-by: Scott Watson <scottywatson07@gmail.com>