most of code implemented