improved filetype detection
Added some utility functions
Made error messages more friendly