Make sure that thumbnail side is not bigger than set maximum size.
Also some reorganizing and renaming