Now the code really works and does what it's supposed to, more or less.