Added more code that wasn't committed and may be broken. Note that this code is probably broken, so it should be used as an example only for when the code is organized in the future.