Added Error Codes and improved Error Handling