Added a bit more code, but it's a work in progress.