Implementation finished. Need to make it proper and add comments