Check format with identify

I kinda refactored everything. see commits for details. hope that's okay.

i tried to make it non-dependant on libraries.