Make scripts not simply rely on extension to determine file format,
check MAGIC number.
Added some utils functions + Refactored
Merged extension branch