removed debugging comments and tidied up