add some comments. this code is not that clear...