A little tidying up, bugfixing