Fixing bitmasks and adding comments.