Improve file types and size checks

And make it a parameter