fixes screwed math, adds logging