changed image scaling algorithm