Modify some functions to show log on error and exit instead sending result.
Extend patch function to check patch before apply and accept patches with levels p0…p3.