Modifications and added codes for problem #2