Major refactor continued - this is looking a bit more promising