Modificed the codes according to comments on 11/26/2014