final version of hw5. It fails in a certain case when scaling, but it's too late for me to do anything about it.