optimized to 7 sec which is good enough. File type.cpp. Question is if it really works corrently