setup environment and error check