refined code lots
have nice comments
and tidied up!