fixing rotation bug for images of non std orientation

also little refactor - use one function to rotate and flip