added a testing function. Program logic fully implemented.