added logging and done some minor changes to the code based on some results on the ref switch