factor out stuff. There is a bug in heat though, so this won't work
right now