Some minor changes: removed some unnecessary checks and added some comments.