Works now! Added some tests, too.