Corrected rectangle position inside popup when direction is 'down' or 'right'