added scan implementation of loss, but seems to be slower to compile and just as fast to run