Proper implementation of loss