got rid of state and tidied up DEBUGS