added more comments to code and fixed some minor bugs, but still having problem with fread() return value