improve error management by not using any panic but always returning errors