commented code and tidied up some structures