In a mess
Double-checking logic and added some comments / tidied up a wee bit while i was at it