added comments to most of the methods so that the logic flow is more clear