added comments and fixed main method