added directional code for problem 5