Changed code structure for testability

Huh. I thought it was. Looks like it's not.