Lots of updates!

Updates too numerous to list, the code is a bit messy but it's working!