Though have implemented all function, but what a such messsss.. I want to write a better and clear code