More debugging and some tidying