Added the functionality of friend and refined the code.