Fixed bug (used Cam's solution.