Changed code structure for testability