some cleanup + lossfunctions