Added lots of code that looks like it works (but doesn't yet)