a bit of theory and some more implementation