Apologies for the massive code dump here but I'm trying to make sure that I've provided enough information to help you all understand what I'm doing (which is) trying to get a grip on this new open...