Tidied, added comments