Improved variable and error handling.