added comments, fixed indentation in pseudocode