More profile stuff, tidied some code.