Cleaned the code a bit. Fixed the extension bit masks.