Fixed issues with error reporting and added define seting function