added return values as rgb, fixed potential division by zero