Improved error handing, fixed data usage