Added end* commands for easier error handling, updated example code.