initial import
more explicit error messages
split code for testing purpose