refactor code for scale and translate