Comments added, code tidied