Make API more secure and fix error reporting