Improved validation and debugging stuff