More error handling and validation