redesigned the code using tdd