Made the min()/max() helper functions external and simplified some code
in the frame server and made cropping more secure.