Fleshed out the logic and test code