Refactored/Added a bit to accomodate testing.