Gives correct output