WIP - another crack at it, I think this is much cleaner