perspective correction and cleaner code